package com.example.apiproject.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.apiproject.dao.JoinArticleDao;
import com.example.apiproject.entity.Articles;
import com.example.apiproject.entity.JoinArticle;
import com.example.apiproject.jwt.jwtutil;
import com.example.apiproject.service.JoinArticleService;
import com.example.apiproject.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class JoinArticleServiceImpl implements JoinArticleService {

    @Autowired
    private JoinArticleDao joinArticleDao;

    @Autowired
    private jwtutil jwtUtil;
    @Override
    public int add(int userId, String id) {
//        String token = request.getHeader("token");
//        if(StringUtils.isBlank(token)){
//            token = request.getParameter("token");
//        }
//        int  userId = jwtUtil.getUserId(token);
        JoinArticle joinArticle = new JoinArticle();
        joinArticle.setArticleId(id);
        joinArticle.setUserId(userId);
        joinArticle.setStatus(1);
        joinArticle.setCreateTime(LocalDateTime.now());
       return joinArticleDao.insert(joinArticle);

    }

    @Override
    public int update(JoinArticle joinArticle) {
      return  joinArticleDao.update(joinArticle);
    }
//    @Override
//    public List<Articles> test() {
//        return joinArticleDao.test(LocalDateTime.now());
//    }
}
